using Game;
using System;
using System.Xml.Linq;
using Engine;

namespace StyleSurvivalcraft;

public class StyleDialog : Dialog
{
    public StyleDialog styleDialog;
    public StyleDialog(string title, string content, Action action)
    {
        XElement xelement = ContentManager.Get<XElement>("Dialogs/StyleDialog", null); 
        base.LoadContents(this, xelement);
        this.m_okButton = this.Children.Find<ButtonWidget>("OkButton", true);
        this.m_titleLabel = this.Children.Find<LabelWidget>("TitleLabel", true);
        this.m_contentLabel = this.Children.Find<LabelWidget>("ContentLabel", true);
        this.m_buttonLabel = this.Children.Find<LabelWidget>("ButtonLabel", true); 
        this.m_scrollPanel = this.Children.Find<ScrollPanelWidget>("ScrollPanel", true); 
        this.m_buttonLabel.Text = LanguageControl.Ok; 
        this.m_okButton.IsVisible = false; 
        this.m_titleLabel.Text = title; 
        this.m_contentLabel.Text = content; 
        this.Action = action;
    }
    public override void Update()
    {
        float num = Math.Max(this.m_scrollPanel.m_scrollAreaLength - this.m_scrollPanel.ActualSize.Y, 0f); 
        if (this.m_scrollPanel.ScrollPosition >= num * 0.6f && this.m_scrollPanel.m_scrollAreaLength != 0f) 
        { 
            this.m_okButton.IsVisible = true;
        } 
        if (this.m_okButton.IsClicked) 
        { 
            this.Action.Invoke(); 
            DialogsManager.HideDialog(this);
        }
    }
        
    public LabelWidget m_titleLabel; 
    public LabelWidget m_contentLabel; 
    public LabelWidget m_buttonLabel;
    public ButtonWidget m_okButton; 
    public ScrollPanelWidget m_scrollPanel;
    public float m_areaLength; 
    public Action Action; 
}